home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / amigadoslibrary / exnext.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  2KB  |  69 lines

  1. /* ExNext.c   V1.0   93-09-27                        */
  2. /* ROM library: "dos.library/ExNext", (All versions) */
  3. /* Copyright 1993, Anders Bjerin, Amiga C Club       */
  4.  
  5. #include <dos/dos.h>
  6. #include <exec/memory.h>
  7.  
  8. #include <clib/dos_protos.h>
  9. #include <clib/exec_protos.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. UBYTE *version = "$VER: ExNext 1.0";
  14.  
  15. int main( int argc, char *argv[] );
  16. int main( int argc, char *argv[] )
  17. {
  18.   BPTR my_lock;
  19.   struct FileInfoBlock *my_fib;
  20.  
  21.  
  22.   /* 1. Lock the directory: */
  23.   my_lock = Lock( "RAM:", SHARED_LOCK );
  24.   if( !my_lock )
  25.   {
  26.     printf( "Could not lock the object!\n" );
  27.     exit( 20 );
  28.   }
  29.  
  30.   /* 2. Allocate a FileInfoBlock structure:  */
  31.   my_fib = (struct FileInfoBlock *)
  32.      AllocMem( sizeof( struct FileInfoBlock ), MEMF_ANY | MEMF_CLEAR );
  33.   if( !my_fib )
  34.   {
  35.     printf( "Not enough memory!\n" );
  36.     UnLock( my_lock );
  37.     exit( 21 );
  38.   };
  39.  
  40.   /* 3. Examine the locked object: */
  41.   if( Examine( my_lock, my_fib ) )
  42.   {
  43.     /* 4. Check if it is a directory or volume: */
  44.     if( my_fib->fib_DirEntryType > 0 )
  45.     {
  46.       printf( "%s\n", my_fib->fib_FileName );
  47.  
  48.       /* 5. As long as we find objects we stay in the loop: */
  49.       while( ExNext( my_lock, my_fib ) )
  50.         printf( "  %s\n", my_fib->fib_FileName );
  51.  
  52.       /* Were all objects listed? */
  53.       if( IoErr() == ERROR_NO_MORE_ENTRIES )
  54.         printf( "No more files!\n" );
  55.       else
  56.         printf("Error while reading!\n");
  57.     }
  58.     else
  59.       printf( "This program needs a directory or volume name!\n" );
  60.   }
  61.   else
  62.     printf( "Could not examine the object!\n" );
  63.  
  64.   FreeMem( my_fib, sizeof( struct FileInfoBlock ) );
  65.   UnLock( my_lock );  
  66.   exit( 0 );
  67. }
  68.  
  69.